home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / RoboticInvaders.dxr / 00007_Particle Engine.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  3.4 KB  |  90 lines

  1. global bgOffset
  2.  
  3. on init_ParticleConstants
  4.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, p_lockParticles, p_LockPic, p_StartSize, p_ScaleRate, p_RotatePic
  5.   p_StartSprite = 150
  6.   p_MaxParticles = 10
  7.   p_MaxFrames = [20, 11, 7, 4, 20]
  8.   p_FrameDelay = [1, 1, 1, 1, 1]
  9.   p_FrameTitle = ["Blast", "SBlast", "tBlast", "Laser", "Gran-daddy-metal"]
  10.   p_StartFade = [100, 100, 100, 100, 50]
  11.   p_FadeIncrement = -2
  12.   p_InkType = 37
  13.   p_SpawnTimer = 0
  14.   p_RandomFlip = 0
  15.   p_RotatePic = 1
  16.   p_LockPic = 0
  17.   p_StartSize = point(6, 15)
  18.   p_ScaleRate = point(0, 0)
  19.   p_lockParticles = 1
  20. end
  21.  
  22. on init_Particles
  23.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, particleData
  24.   particleData = []
  25.   repeat with wEntry = 1 to p_MaxParticles
  26.     wSprite = p_StartSprite + wEntry - 1
  27.     add(particleData, [0, 0, 0, point(0, 0)])
  28.     sprite(wSprite).visible = 0
  29.     puppetSprite(wSprite, 1)
  30.     set the member of sprite wSprite to p_FrameTitle[1] & " 1"
  31.     set the ink of sprite wSprite to p_InkType
  32.     set the loc of sprite wSprite to point(0, 0)
  33.     sprite(wSprite).locZ = 450
  34.   end repeat
  35. end
  36.  
  37. on addparticle spawnPoint, SpawnRotate, spawnType
  38.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, p_RotatePic, particleData, p_lockParticles
  39.   if p_lockParticles = 1 then
  40.     validSlot = 0
  41.     repeat with wSlot = 1 to p_MaxParticles
  42.       if (validSlot = 0) and (particleData[wSlot][1] = 0) then
  43.         validSlot = wSlot
  44.       end if
  45.     end repeat
  46.     if validSlot <> 0 then
  47.       particleData[validSlot] = [spawnType, 0, 0, spawnPoint]
  48.       wSprite = p_StartSprite + validSlot - 1
  49.       set the loc of sprite wSprite to spawnPoint + bgOffset
  50.       set the member of sprite wSprite to p_FrameTitle[spawnType] & " 1"
  51.       set the blend of sprite wSprite to p_StartFade[spawnType]
  52.       sprite(wSprite).rotation = SpawnRotate
  53.       sprite(wSprite).visible = 1
  54.     end if
  55.   end if
  56. end
  57.  
  58. on moveParticles
  59.   global p_StartSprite, p_MaxParticles, p_MaxFrames, p_FrameDelay, p_FrameTitle, p_StartFade, p_FadeIncrement, p_InkType, p_SpawnTimer, p_LockPic, p_StartSize, p_ScaleRate, particleData, playerViewPoint
  60.   playerViewPoint = point(0, 0)
  61.   p_SpawnTimer = p_SpawnTimer + 1
  62.   if p_SpawnTimer > 36500 then
  63.     p_SpawnTimer = 1
  64.   end if
  65.   repeat with wEntry = 1 to p_MaxParticles
  66.     wSprite = p_StartSprite + wEntry - 1
  67.     if particleData[wEntry][1] <> 0 then
  68.       eType = particleData[wEntry][1]
  69.       if particleData[wEntry][3] <= 1 then
  70.         particleData[wEntry][3] = p_FrameDelay[eType]
  71.         particleData[wEntry][2] = particleData[wEntry][2] + 1
  72.         if particleData[wEntry][2] > p_MaxFrames[eType] then
  73.           particleData[wEntry][1] = 0
  74.           sprite(wSprite).visible = 0
  75.         else
  76.           if (p_LockPic = 0) and (eType <> 5) then
  77.             set the member of sprite wSprite to p_FrameTitle[eType] & " " & string(particleData[wEntry][2])
  78.           else
  79.             set the blend of sprite wSprite to p_StartFade[eType] + (p_FadeIncrement * particleData[wEntry][2])
  80.           end if
  81.         end if
  82.       else
  83.         particleData[wEntry][3] = particleData[wEntry][3] - 1
  84.       end if
  85.       set the loc of sprite wSprite to particleData[wEntry][4] - playerViewPoint + bgOffset
  86.       next repeat
  87.     end if
  88.   end repeat
  89. end
  90.